package com.bio.dao.task.impl;

import org.hibernate.criterion.Restrictions;
import com.bio.dao.impl.HibernateDaoImpl;
import com.bio.dao.impl.HibernateQuery;
import com.bio.dao.task.TaskDao;
import com.bio.entity.task.Task;
import com.bio.utils.Pager;
import com.bio.utils.Pagination;

public class TaskDaoImpl extends HibernateDaoImpl<Task> implements TaskDao{

	@Override
	public Pager<Task> findPagerByUserId(Pagination pagination,
			Long userId, Long companyId) {
		
		HibernateQuery<Task> hq = new HibernateQuery<Task>(this.getSessionFactory(), 
				this.getSession(), Task.class).setPagination(pagination);
		if(null != userId){
			hq.addWhere(Restrictions.eq("ownerId",userId));
		} else {
			hq.addWhere(Restrictions.isNull("owenrId"));
		}
		if(null != companyId){
			hq.addWhere(Restrictions.eq("companyId",companyId));
		} else {
			hq.addWhere(Restrictions.isNull("companyId"));
		}
		
		return hq.query();
	}

}
